

package com.sql.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class jdbc02 {
    public static void main(String[] args) {
        try {
            // 加载 MySQL 驱动，这里假设使用 MySQL 8.0 驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/ztm";
            String user = "root";
            String password = "123456789";
            Connection connection = DriverManager.getConnection(url, user, password);
            System.out.println("数据库连接成功");
            connection.close();
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }
}
